package com.hue.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hue.entity.CrmBanner;
import com.hue.entity.R;
import com.hue.service.CrmBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author 姚凤桥
 * @since 2021-07-03
 */
@RestController
@RequestMapping("/crm-banner/admin")
@CrossOrigin
public class CrmBannerAdminController {
    @Autowired
    private CrmBannerService crmBannerService;

    //分页查询
    @GetMapping("/findPage/{page}/{size}")
    public R findPage(@PathVariable("page") int page,
                      @PathVariable("size") int size) {
        Page<CrmBanner> crmBannerPage = new Page<>(page, size);
        crmBannerService.page(crmBannerPage, null);
        return R.ok().data("crmBannerPage", crmBannerPage);
    }

    //增加
    @PostMapping("/addCrmBanner")
    public R addCrmBanner(@RequestBody CrmBanner crmBanner) {
        boolean b = crmBannerService.save(crmBanner);
        return b ? R.ok() : R.error();
    }

    //删除
    @GetMapping("/removeById/{id}")
    public R removeById(@PathVariable("id") String id) {
        return crmBannerService.removeById(id) ? R.ok() : R.error();
    }

    //修改
    @GetMapping("/update")
    public R update(@RequestBody CrmBanner crmBanner) {
        boolean b = crmBannerService.updateById(crmBanner);
        return b ? R.ok() : R.error();
    }
}

